import Vue from 'vue'

// 重置css默认样式
import 'normalize.css/normalize.css' // A modern alternative to CSS resets

// 导入ElementUI及对应样式
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

//
import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
import request from './utils/request'

// 不带from有导入并执行的作用
import '@/icons' // icon
import '@/permission' // permission control

// import { imgerror, color } from '@/directives'
// Vue.directive('imgerror', imgerror)
// Vue.directive('color', color)

import * as directives from '@/directives'
// console.log(directives)

// 遍历得到的对象, 批量进行自定义指令的注册
// for (const key in directives) {
//   Vue.directive(key, directives[key])
// }

// 批量注册全局的自定义指令
Object.keys(directives).forEach(key => {
  Vue.directive(key, directives[key])
})
// Vue.directive('imgerror', {
//   inserted(el, binding) {
//     // el是标签
//     // binding.value是自定义属性的值即errimg
//     // console.log(binding.value)
//     el.onerror = function() {
//       el.src = binding.value
//     }
//   }
// })
// Vue.directive('color', {
//   inserted(el, binding) {
//     el.style.color = binding.value
//   }
// })
// 一般全局注册组件
// import PageTools from '@/components/PageTools'
// Vue.component('PageTools', PageTools)
import components from '@/components'
// 使用插件在使用vue.use时，会自动调用插件的install方法
Vue.use(components)
// 下面没用
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
Vue.use(ElementUI)
Vue.prototype.$request = request
Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
